package com.qf.controller;

import com.qf.pojo.Customer;
import com.qf.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 查询缓存
 * @author lixu
 */
@RestController
@RequestMapping("/cache")
public class CacheController {

    @Autowired
    private CustomerService customerService;
    /**
     * 测试
     */
    @GetMapping("/{id}")
    public Customer findById(@PathVariable Integer id){

        Customer c1 = customerService.findById(id);//远程调用查询
        System.out.println("查询到了:" + c1);
        Customer c2 = customerService.findById(id);//查询的缓存
        System.out.println("查询到了:" + c2);

        //清理缓存是好用的
        customerService.clearFindById(id);//清理Filter过滤器的缓存

        //c3: 又要去远程调用查询
        Customer c3 = customerService.findById(id);//远程调用查询
        System.out.println("查询到了:" + c3);
        Customer c4 = customerService.findById(id);//查询的缓存
        System.out.println("查询到了:" + c4);

        return c1;
    }
}
